// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PRODUCT_SERVICE_GROUP_EHC_E01 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("14 PSG",14)]
  	    [HL7Field(HL7Version.v26, 14, HL7Repeat.False, HL7Required.True,"PSG")]
	    public PSG PSG {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("15 LOC",15)]
  	    [HL7Field(HL7Version.v26, 15, HL7Repeat.True, HL7Required.False,"LOC")]
	    public LOC[] LOC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("16 ROL",16)]
  	    [HL7Field(HL7Version.v26, 16, HL7Repeat.True, HL7Required.False,"ROL")]
	    public ROL[] ROL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("17 PATIENT_INFO",17)]
  	    [HL7Field(HL7Version.v26, 17, HL7Repeat.True, HL7Required.False,"PATIENT_INFO_EHC_E01")]
	    public PATIENT_INFO_EHC_E01[] PATIENT_INFO {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("32 PRODUCT_SERVICE_LINE_ITEM",32)]
  	    [HL7Field(HL7Version.v26, 32, HL7Repeat.True, HL7Required.True,"PRODUCT_SERVICE_LINE_ITEM_EHC_E01")]
	    public PRODUCT_SERVICE_LINE_ITEM_EHC_E01[] PRODUCT_SERVICE_LINE_ITEM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("40 PROCEDURE",40)]
  	    [HL7Field(HL7Version.v26, 40, HL7Repeat.True, HL7Required.False,"PROCEDURE_EHC_E01")]
	    public PROCEDURE_EHC_E01[] PROCEDURE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("45 INVOICE_PROCESSING",45)]
  	    [HL7Field(HL7Version.v26, 45, HL7Repeat.True, HL7Required.False,"INVOICE_PROCESSING_EHC_E01")]
	    public INVOICE_PROCESSING_EHC_E01[] INVOICE_PROCESSING {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PSG = PopSegmentParseAndCheckRequired<PSG>(availableData, options, "PSG");
			LOC = PopSegmentParseAndCheckRequiredArray<LOC>(availableData, options, "LOC");
			ROL = PopSegmentParseAndCheckRequiredArray<ROL>(availableData, options, "ROL");
			PATIENT_INFO = ProcessGroupArray<PATIENT_INFO_EHC_E01>(availableData, options, "PATIENT_INFO");
			PRODUCT_SERVICE_LINE_ITEM = ProcessGroupArray<PRODUCT_SERVICE_LINE_ITEM_EHC_E01>(availableData, options, "PRODUCT_SERVICE_LINE_ITEM");
			PROCEDURE = ProcessGroupArray<PROCEDURE_EHC_E01>(availableData, options, "PROCEDURE");
			INVOICE_PROCESSING = ProcessGroupArray<INVOICE_PROCESSING_EHC_E01>(availableData, options, "INVOICE_PROCESSING");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPSG = availableData.StartsWith("PSG", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PSG", options.Version) || isPSG) {
				return isPSG;
			}
			bool isLOC = availableData.StartsWith("LOC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("LOC", options.Version) || isLOC) {
				return isLOC;
			}
			bool isROL = availableData.StartsWith("ROL", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ROL", options.Version) || isROL) {
				return isROL;
			}
			PATIENT_INFO_EHC_E01 testPATIENT_INFO_EHC_E01 = new PATIENT_INFO_EHC_E01();
			bool grpCCPATIENT_INFO_EHC_E01 = (testPATIENT_INFO_EHC_E01.CanConsume(availableData, options));
			if (IsRequired("PATIENT_INFO", options.Version) || grpCCPATIENT_INFO_EHC_E01) {
				return grpCCPATIENT_INFO_EHC_E01;
			}
			PRODUCT_SERVICE_LINE_ITEM_EHC_E01 testPRODUCT_SERVICE_LINE_ITEM_EHC_E01 = new PRODUCT_SERVICE_LINE_ITEM_EHC_E01();
			bool grpCCPRODUCT_SERVICE_LINE_ITEM_EHC_E01 = (testPRODUCT_SERVICE_LINE_ITEM_EHC_E01.CanConsume(availableData, options));
			if (IsRequired("PRODUCT_SERVICE_LINE_ITEM", options.Version) || grpCCPRODUCT_SERVICE_LINE_ITEM_EHC_E01) {
				return grpCCPRODUCT_SERVICE_LINE_ITEM_EHC_E01;
			}
			PROCEDURE_EHC_E01 testPROCEDURE_EHC_E01 = new PROCEDURE_EHC_E01();
			bool grpCCPROCEDURE_EHC_E01 = (testPROCEDURE_EHC_E01.CanConsume(availableData, options));
			if (IsRequired("PROCEDURE", options.Version) || grpCCPROCEDURE_EHC_E01) {
				return grpCCPROCEDURE_EHC_E01;
			}
			INVOICE_PROCESSING_EHC_E01 testINVOICE_PROCESSING_EHC_E01 = new INVOICE_PROCESSING_EHC_E01();
			bool grpCCINVOICE_PROCESSING_EHC_E01 = (testINVOICE_PROCESSING_EHC_E01.CanConsume(availableData, options));
			if (IsRequired("INVOICE_PROCESSING", options.Version) || grpCCINVOICE_PROCESSING_EHC_E01) {
				return grpCCINVOICE_PROCESSING_EHC_E01;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PRODUCT_SERVICE_GROUP";
			}
        }

        static PRODUCT_SERVICE_GROUP_EHC_E01() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PRODUCT_SERVICE_GROUP_EHC_E01));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PSG != null) {
			string segmentValue = PSG.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (LOC != null && LOC.Length > 0) {
			for (int i = 0; i < LOC.Length; i++) {
				string segmentValue = LOC[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (ROL != null && ROL.Length > 0) {
			for (int i = 0; i < ROL.Length; i++) {
				string segmentValue = ROL[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PATIENT_INFO != null && PATIENT_INFO.Length > 0) {
			for (int i = 0; i < PATIENT_INFO.Length; i++) {
				string segmentValue = PATIENT_INFO[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PRODUCT_SERVICE_LINE_ITEM != null && PRODUCT_SERVICE_LINE_ITEM.Length > 0) {
			for (int i = 0; i < PRODUCT_SERVICE_LINE_ITEM.Length; i++) {
				string segmentValue = PRODUCT_SERVICE_LINE_ITEM[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PROCEDURE != null && PROCEDURE.Length > 0) {
			for (int i = 0; i < PROCEDURE.Length; i++) {
				string segmentValue = PROCEDURE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (INVOICE_PROCESSING != null && INVOICE_PROCESSING.Length > 0) {
			for (int i = 0; i < INVOICE_PROCESSING.Length; i++) {
				string segmentValue = INVOICE_PROCESSING[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

